package entities;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Date;


/**
 * The persistent class for the logins database table.
 * 
 */
@Entity
@Table(name="logins")

@NamedQueries({

	@NamedQuery(name="getUserLogginLastAccess", 
		query="SELECT x.lastAccess FROM Login x WHERE x.userprofile.email=:email"),
		
	@NamedQuery(name="getUserLoggin", 
				query="SELECT x FROM Login x WHERE x.userprofile.email=:email"),
		
	@NamedQuery(name="validateUserLoggin", 
		query="SELECT x.id FROM Login x WHERE x.userprofile.email=:email AND x.passwordHashed=:pass")

})

public class Login implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="Id", unique=true, nullable=false)
	private int id;

    @Temporal( TemporalType.TIMESTAMP)
	@Column(name="LastAccess", nullable=false)
	private Date lastAccess;

	@Column(name="PasswordHashed", nullable=false, length=45)
	private String passwordHashed;

	//bi-directional many-to-one association to Userprofile
    @ManyToOne
	@JoinColumn(name="UserId", nullable=false)
	private Userprofile userprofile;

    public Login() {
    }

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getLastAccess() {
		return this.lastAccess;
	}

	public void setLastAccess(Date lastAccess) {
		this.lastAccess = lastAccess;
	}

	public String getPasswordHashed() {
		return this.passwordHashed;
	}

	public void setPasswordHashed(String passwordHashed) {
		this.passwordHashed = passwordHashed;
	}

	public Userprofile getUserprofile() {
		return this.userprofile;
	}

	public void setUserprofile(Userprofile userprofile) {
		this.userprofile = userprofile;
	}
	
}